/**
 * 
 */
package io.dora.conf;

import io.dora.registry.zk.ZkUtils;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Provider Config Bean
 * 
 * @author zhaohongbo
 *
 */
public class ProviderConfig<T> extends AbstractServiceConfig implements Provider<T> {
	
	private Logger logger = LoggerFactory.getLogger(ProviderConfig.class);

	/** 服务分组，别名 */
	protected String group;

	/** 服务引用 */
	protected T ref;

	/** 服务接口class */
	protected Class<?> interfaceClass;

	/** 引用的Bean ID */
	protected String refBeanId;
	
	public String getGroup() {
		return group;
	}
	public void setGroup(String group) {
		this.group = group;
	}
	
	public T getRef() {
		return ref;
	}

	public void setRef(T ref) {
		this.ref = ref;
	}

	public Class<?> getInterfaceClass() {
		return interfaceClass;
	}

	public void setInterfaceClass(Class<?> interfaceClass) {
		this.interfaceClass = interfaceClass;
	}
	
	public String getRefBeanId() {
		return refBeanId;
	}
	
	public void setRefBeanId(String refBeanId) {
		this.refBeanId = refBeanId;
	}

	@Override
	public void export() {
		System.out.println(ToStringBuilder.reflectionToString(protocol));
		logger.info("Export service:[{}]", this.getInterfaceClass().getName());
		protocol.export(this);
	}

	/**
	 * 获取服务KEY
	 *
	 * @return
	 */
	public String getServiceKey() {
		return ZkUtils.separator + group + ZkUtils.separator + interfaceClass.getName();
	}
}
